package com.zrf.geekbang.spring.dependency.lookup;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @Configuration是一个非必须的注解
 * @author zhouruifeng
 * @date 2020-07-05
 */
public class ObjectProviderDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //注入配置类
        applicationContext.register(ObjectProviderDemo.class);
        //启动应用上下文
        applicationContext.refresh();

        lookupByObjectProvider(applicationContext);
    }

    private static void lookupByObjectProvider(AnnotationConfigApplicationContext applicationContext ) {
        ObjectProvider<String> beanProvider = applicationContext.getBeanProvider(String.class);
        System.out.println(beanProvider.getObject());
    }

    /**
     * BeanName == method Name
     * @return
     */
    @Bean
    private String helloWorld() {
        return "helloWorld";
    }
}
